﻿// -----------------------------------------------------------------------
//  <copyright file="GetTodoItemPageQuery.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2025 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025-08-15 21:08</last-date>
// -----------------------------------------------------------------------

using OSharp.Filter;


namespace Todos.Application.TodoItems.Queries;

[AuthConfig(typeof(TodoItem), ResourceAccessType.RoleLimit, "GetPage")]
public class GetTodoItemPageQuery : PageQuery<PageResult<TodoItemOutDto>>
{
    public long ListId { get; set; }
}

public class GetTodoItemPageQueryHandler(IQueryRepository<TodoItem> repository) : IRequestHandler<GetTodoItemPageQuery, PageResult<TodoItemOutDto>>
{
    public async Task<PageResult<TodoItemOutDto>> Handle(GetTodoItemPageQuery request, CancellationToken cancellationToken)
    {
        var spec = new PageQuerySpecification<TodoItem>(request.PageCondition, request.FilterGroup)
            .And(new TodoItemByListIdSpec(request.ListId));
        var page = await repository.GetPageAsync<TodoItemOutDto>(spec, cancellationToken);
        return page;
    }
}